package com.evenmo.hrms.mapper.oldmapper;

import com.evenmo.hrms.mapper.oldmapper.dynaSqlProvider.DocumentDynaSqlProvider;
import com.evenmo.hrms.pojo.Document;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

@Mapper
public interface DocumentMapper {


    // 动态查询

    /**
     * 动态查询
     *
     * @param document 查询对象参数
     * @return 符合条件的文档
     */
    @SelectProvider(type = DocumentDynaSqlProvider.class, method = "selectByParams")

    @Results(id = "documentResultHaveUser", value = {@Result(column = "userId", property = "userId"),
            @Result(column = "userId", property = "user", one = @One(select = "com.evenmo.hrms.mapper.oldmapper.UserMapper.selectById", fetchType = FetchType.EAGER))})
// 结果集设置映射关系是可以分开设置，也可以放在@Results中以数组的方式
//    @Result(column = "userId",property = "userId")
//    @Result(column = "userId",property = "user",one=@One(select = "com.evenmo.hrms.mapper.oldmapper.UserMapper.selectById",fetchType = FetchType.EAGER))
    public List<Document> selectByParams(Document document);
    // 动态插入

    /**
     * 动态插入
     *
     * @param document 插入的文档对象参数
     * @return 插入的数目
     */
    @InsertProvider(type = DocumentDynaSqlProvider.class, method = "insertByParams")
    public int insertByParams(Document document);
    // 根据ID删除文档

    /**
     * 根据ID删除文档
     *
     * @param id 文档ID
     * @return 符合条件的文档
     */
    @Delete("delete from document where id=#{id}")
    public int deleteById(Integer id);
    // 根据ID查询文档

    /**
     * 根据ID查询文档
     *
     * @param id 文档ID
     * @return 符合条件的文档
     */
    @Select("select * from document where id=#{id}")
    @ResultMap("documentResultHaveUser")
    public Document selectById(Integer id);

    // 动态修改文档
    @UpdateProvider(type = DocumentDynaSqlProvider.class, method = "updateByParams")
    public int updateByParams(Document document);

    /**
     * 查询所有的文档
     *
     * @return 所有的文档列表
     */
    public List<Document> selectDocuments();
}
